import { onMounted, ref } from "vue";

export const useScale = function () {
    const style = ref<any>({});
    onMounted(() => {
        const temp = document.querySelector('meta[name="viewport"]');
        if (!temp) {
            console.log("has meta");
            var meta = document.createElement("meta");
            meta.name = "viewport";
            meta.content = "user-scalable=no,width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0";
            // 将 meta 标签添加到 head 中
            document.head.appendChild(meta);

            logs();
        }
        setTimeout(resize, 30);
        setTimeout(resize, 120);
        setTimeout(resize, 300);

    });
    return { style };
};

function resize(){
    let dom: any = document.querySelector(".bbs");
    // alert(window.innerWidth + "/" + dom.clientWidth + "," + window.devicePixelRatio);
    if (dom) {
        let n = (window.innerWidth / dom.clientWidth) * 0.9;
        dom.style.transform = `scale(${n})`;
    }
}

function logs() {
    if (localStorage.getItem("logs") == "1") {
        var script = document.createElement("script");
        script.src = "https://cdn.jsdelivr.net/npm/eruda";
        document.body.append(script);
        script.onload = function () {
            (window as any).eruda.init();
        };
        localStorage.removeItem("logs");
    }
}
